﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DATA
{
  public class PositionREP
  {
      MODELGENERALDataContext context = new MODELGENERALDataContext();
      public List<PositionDTO> GetAllPositions()
        {
            List<PositionDTO> acc = new List<PositionDTO>();
            var acounts = from a in context.Positions
                          select a;
            PositionDTO posDTO;
            foreach (var account in acounts)
            {
                posDTO = new PositionDTO();
                posDTO.Description = account.description;
                posDTO.IsActived = account.isActived;
                posDTO.PositionID = account.positionID;
                posDTO.PositionName = account.positionName;
                acc.Add(posDTO);
            }
            return acc;
        }

      public bool UpdatePosition(PositionDTO pos)
      {
          try
          {
              Position acc = context.Positions.Single(nv => nv.positionID == pos.PositionID);
              acc.positionName = pos.PositionName;
              acc.isActived = pos.IsActived;
              acc.description = pos.Description;
              context.SubmitChanges();
          }
          catch (System.Exception ex)
          {
              return false;
          }
          return true;
      }


  }
}
